package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.List;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;

import com.example.obj.ContactObject;
import com.example.obj.ContactSet;

public class Test_08_PhonesPrint extends TestBase {
	
	@Test(priority = 3)
	public void testPhonesCanBePrinted(){
		log.info("Start testPhonesCanBePrinted");
		List<ContactObject> contactList = manager.getHibernateHelper().getContactList();	
		for (ContactObject contact : contactList) {
			contact.setId("");
		}
		log.info("Contacts list: " + contactList);
		List<ContactObject> printContacts = manager.getContactHelper().getPrintContacts();
		log.info("Printed contacts list: " + printContacts);
		log.info("Start assertions: size, order, lists' elements");	
		assertThat(printContacts.size(), equalTo(contactList.size()));
		assertThat(printContacts, equalTo(contactList));
	}
	
	@AfterMethod
	public void testUIConfirmWithDB(){
		log.info("After testPhonesCanBePrinted");
		ContactSet contactsUI = manager.getContactHelper().getContactsUI();
		log.info("Contacts from UI: " + contactsUI);		
		ContactSet contactsDB = manager.getContactHelper().getCacheCopy();
		log.info("Contacts from DB: " + contactsDB);
		assertThat(contactsDB, equalTo(contactsUI));
	}
}
